<div style="float: right;">
    <a href="<?=base_url("no_edit/sticker/add_sticker_type")?>" class="layui-btn">新建分类</a>
    <button class="layui-btn fabu">发布</button>
</div>
<br><br>
<br><br>
<div class="layui-collapse">
    <?php if(!empty($data)){
    foreach($data as $k=>$v){
    $length=count($data);//统计这个数组有多少个
    ?>
    <!--    <div class="layui-colla-item dd--><?//=$k;?><!--">-->
    <div class="dd<?=$k;?>">
        <h2 class="layui-colla-title">
            <span style="color:blue;"><?=$v['test_sticker_type_name']?></span>
            <?php if($v['test_status']==1){ ?>
                <button class="layui-btn layui-btn-normal layui-btn-xs use<?=$k;?>" style="float: right;margin-top: 10px;margin-right: 20px;">启用</button>
            <?php }else if($v['test_status']==2){ ?>
                <button class="layui-btn layui-btn-danger layui-btn-xs stop<?=$k;?>" style="float: right;margin-top: 10px;margin-right: 20px;">停用</button>
            <?php } ?>
            <button class="layui-btn layui-btn-xs edit<?=$k;?>" style="float: right;margin-top: 10px;">编辑</button>
            <button class="layui-btn layui-btn-normal layui-btn-xs down<?=$k;?>" style="float: right;margin-top: 10px;margin-right: 20px;">下移</button>
            <button class="layui-btn layui-btn-xs up<?=$k;?>" style="float: right;margin-top: 10px;">上移</button>
        </h2>
        <div class="layui-colla-content layui-show">
            <?php if(!empty($v['children'])){
                foreach($v['children'] as $kk=>$vv){
                    ?>
                    <div class="layui-input-inline" style="width:100px;height:140px;margin-left:8px;margin-right:8px;margin-bottom:20px;">
                        <img src="<?=$vv['icon']?>" class="tom_show_image" style="width:100px;height:100px;">
                        <p><?=$vv['sticker_name']?></p>
                    </div>
                    <!--            <img src="--><?//=$vv['icon']?><!--" style="width:100px;height:100px;">-->
                    <!--            <span>--><?//=$vv['sticker_name']?><!--</span>        -->
                <?php }}else{ ?>
            <div style="width:100px;height:50px;">
                <?php } ?>
            </div>
        </div>
        <input type="hidden" value="<?=$v['id']?>" class="now<?=$k;?>">
        <?php if($k==0){ ?>
            <input type="hidden" name="" value="<?=$data[0]['id']?>" class="start<?=$k;?>">
        <?php }else{ ?>
            <input type="hidden" name="" value="<?=$data[$k-1]['id']?>" class="start<?=$k;?>">
        <?php } ?>
        <?php if($k==$length-1){ ?>
            <input type="hidden" name="" value="<?=$data[$length-1]['id']?>" class="end<?=$k;?>">
        <?php }else{ ?>
            <input type="hidden" name="" value="<?=$data[$k+1]['id']?>" class="end<?=$k;?>">
        <?php } ?>
        <?php }}else{ ?>
            <tr>
                <td colspan="7" rowspan="3" style="color: #00CC00;font-size: 25px;height:100px;text-align: center;">暂无数据</td>
            </tr>
        <?php } ?>
    </div>
    <script>
        $(".fabu").click(function(){
            $.ajax({
                type: "post",
                data: {},
                dataType: "json",
                url: "<?=base_url("no_edit/sticker/fabu")?>",
                success: function (res) {
                    if(res.code==0){
                        layer.msg(res.msg, {time: 2000},function(){
                            window.location.reload();
                        });
                    }else{
                        layer.msg(res.msg, {time: 2000});
                    }
                }
            })
        })
        $(function(){
            //定义一个50的jquery数组
            var arr=new Array(50);
            for(var i=0;i<50;i++){
                arr.push(i);
            }
            $.each(arr,function(i,n){
                //编辑
                $('.edit'+n).click(function(event){
                    var now=$('.now'+n).val();
                    var url="<?=base_url("no_edit/sticker/edit?id=")?>";
                    var jump_url=url+now;
                    window.location.href=jump_url;
                    event.stopPropagation();
                })

                //停用
                $('.stop'+n).click(function(event){
                    var now=$('.now'+n).val();
                    $.ajax({
                        type: "post",
                        data: {id:now},
                        dataType: "json",
                        url: "<?=base_url("no_edit/sticker/stop")?>",
                        success: function (res) {
                            if(res.code==0){
                                layer.msg(res.msg, {time: 2000},function(){
                                    window.location.reload();
                                });
                            }else{
                                layer.msg(res.msg, {time: 2000});
                            }
                        }
                    })
                    event.stopPropagation();
                })

                //启用
                $('.use'+n).click(function(event){
                    var now=$('.now'+n).val();
                    $.ajax({
                        type: "post",
                        data: {id:now},
                        dataType: "json",
                        url: "<?=base_url("no_edit/sticker/uses")?>",
                        success: function (res) {
                            if(res.code==0){
                                layer.msg(res.msg, {time: 2000},function(){
                                    window.location.reload();
                                });
                            }else{
                                layer.msg(res.msg, {time: 2000});
                            }
                        }
                    })
                    event.stopPropagation();
                })

                //上移
                $('.up'+n).click(function(event){
                    var start=$('.start'+n).val();
                    var now=$('.now'+n).val();
                    var end=$('.end'+n).val();
                    if(start==now){
                        layer.msg("当前已为第一个")
                        return false;
                    }else{
//                    var a=[start,now]
                        $.ajax({
                            type: "post",
                            data: {start:start,now:now,end:end},
                            dataType: "json",
                            url: "<?=base_url("no_edit/sticker/up_sort")?>",
                            success: function (res) {
                                if(res.code==0){
                                    layer.msg(res.msg, {time: 2000},function(){
                                        window.location.reload();
                                    });
                                }else{
                                    layer.msg(res.msg, {time: 2000});
                                }
                            }
                        })
                    }

                    event.stopPropagation();
                })

                //下移
                $('.down'+n).click(function(event){
                    var start=$('.start'+n).val();
                    var now=$('.now'+n).val();
                    var end=$('.end'+n).val();
                    if(end==now){
                        layer.msg("当前已为最后一个")
                        return false;
                    }else{
//                    var a=[start,now]
                        $.ajax({
                            type: "post",
                            data: {start:start,now:now,end:end},
                            dataType: "json",
                            url: "<?=base_url("no_edit/sticker/down_sort")?>",
                            success: function (res) {
                                if(res.code==0){
                                    layer.msg(res.msg, {time: 2000},function(){
                                        window.location.reload();
                                    });
                                }else{
                                    layer.msg(res.msg, {time: 2000});
                                }
                            }
                        })
                    }

                    event.stopPropagation();
                })

            })

            //注意：折叠面板 依赖 element 模块，否则无法进行功能性操作
            layui.use('element', function(){
                var element = layui.element;

                //…
            });
        })

    </script>